from sina import DataSourceSinaImpl
from sohu import DataSourceSohuImpl
from w618 import DataSourceW618Impl
from datasource import DataSource
class DataSourceCfgImpl(DataSource):
    #def add_listener(self,func,user_data):
    def __init__(self):
        self.sina=DataSourceSinaImpl()
        self.sohu=DataSourceSohuImpl()
        self.w618=DataSourceW618Impl()
        self.conn_quot_single=self.sina
        self.conn_quot_multi=self.sina
        self.conn_img=self.sina
        self.impl={"sina":self.sina,"sohu":self.sohu,"w618":self.w618}
    
    def set_config(self,cfg):
        self.cfg=cfg
        self.conn_quot_single=self.impl[cfg["qt_single"]]
        self.conn_quot_multi=self.impl[cfg["qt_multi"]]
        self.conn_img=self.impl[cfg["img"]]
    
    def get_stock_quotation(self,stock_code_list,func=None,user_data=None):
        if(len(stock_code_list)==1):sdl= self.conn_quot_single.get_stock_quotation(stock_code_list,func,user_data)
        else:sdl=self.conn_quot_multi.get_stock_quotation(stock_code_list,func,user_data)
        return sdl
        
    def get_img_to_file(self,stock_code,img_type,path,func=None,user_data=None):
        return self.conn_img.get_img_to_file(stock_code,img_type,path,func,user_data)